<?php

require_once 'phpmoko/externals/JQueryUI.php';
require_once 'phpmoko/ui/RootPanel.php';
require_once 'phpmoko/ui/Form/FormBase.php';

class DateBox extends FormBase
{
	var $value = null;
	var $format = 'mm/dd/yy';
	
	function __construct()
	{
		parent::__construct();

		$this->id = RootPanel::getUniqueId();

		JQueryUI::activate();
	}
	
	function setValue($value)
	{
		$this->value = $value;
	}

	function setFormat($value)
	{
		$this->format = $value;
	}
	
	function toString()
	{
		$str = '<input';

		if ($this->id != null)
			$str .= ' id="'.$this->id.'"';

		if ($this->name != null)
			$str .= ' name="'.$this->name.'"';

		if ($this->style != null)
			$str .= ' class="'.$this->style.'"';

		$str .= ' type="text">';
		
		$root = RootPanel::get();
		
		$js = '$("#'.$this->id.'").datepicker();';

		if ($this->format != null)
			$js.= '$("#'.$this->id.'").datepicker("option", "dateFormat", \''.$this->format.'\');';

		if ($this->value != null)
			$js.= '$("#'.$this->id.'").datepicker("setDate", \''.$this->value.'\');';

		$root->addJSOnReadyDocument($js);
		
		return $str;
	}
}
?>